package qs.openxt.libs.fragment;

import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import qs.openxt.libs.R;

public class BaseStyle implements View.OnClickListener{
	private Activity mActivity = null;
	
	public abstract interface OnBtnActionListener {
		public abstract void onBackAction();
		public abstract void onOKAction();
	}
	
	protected OnBtnActionListener listener = null;
	
	public BaseStyle(Activity a, int viewId, String titleName, boolean hasBack, boolean hasOk) {
		mActivity = a;
		a.setContentView(viewId);
		TextView tv_title = (TextView) a.findViewById(R.id.com_boingpay_tv_name);
		tv_title.setText(titleName);
		Button btn_back = (Button) a.findViewById(R.id.com_boingpay_btn_back);
		if (hasBack) {
			btn_back.setVisibility(View.VISIBLE);
			btn_back.setOnClickListener(this);
		} else
			btn_back.setVisibility(View.GONE);

		Button btn_ok = (Button) a.findViewById(R.id.com_boingpay_btn_ok);
		if (hasOk) {
			btn_ok.setVisibility(View.VISIBLE);
			btn_ok.setOnClickListener(this);
		} else
			btn_ok.setVisibility(View.GONE);
	}
	
	public void setOnBtnActionListener(OnBtnActionListener l){
	    this.listener = l;
	}
	
	@Override
	public void onClick(View v) {
		if(v.getId() == R.id.com_boingpay_btn_back){
			if(this.listener != null)
				this.listener.onBackAction();
			else
				mActivity.finish();
		}else if(v.getId() == R.id.com_boingpay_btn_ok){
			if(this.listener != null)
				this.listener.onOKAction();
		}
	}
}
